using System;
using System.Text;
namespace ns2
{
	internal sealed class Class0
	{
		private GF256 gf256_0;
		private int[] int_0;
		internal int[] method_0()
		{
			return this.int_0;
		}
		internal int method_1()
		{
			return this.int_0.Length - 1;
		}
		internal bool method_2()
		{
			return this.int_0[0] == 0;
		}
		internal Class0(GF256 gf256_1, int[] int_1)
		{
			if (int_1 == null || int_1.Length == 0)
			{
				throw new ArgumentException();
			}
			this.gf256_0 = gf256_1;
			int num = int_1.Length;
			if (num > 1 && int_1[0] == 0)
			{
				int num2 = 1;
				while (num2 < num && int_1[num2] == 0)
				{
					num2++;
				}
				if (num2 == num)
				{
					this.int_0 = gf256_1.Zero.int_0;
				}
				else
				{
					this.int_0 = new int[num - num2];
					Array.Copy(int_1, num2, this.int_0, 0, this.int_0.Length);
				}
			}
			else
			{
				this.int_0 = int_1;
			}
		}
		internal int method_3(int int_1)
		{
			return this.int_0[this.int_0.Length - 1 - int_1];
		}
		internal int method_4(int int_1)
		{
			int result;
			if (int_1 == 0)
			{
				result = this.method_3(0);
			}
			else
			{
				int num = this.int_0.Length;
				if (int_1 == 1)
				{
					int num2 = 0;
					for (int i = 0; i < num; i++)
					{
						num2 = GF256.smethod_0(num2, this.int_0[i]);
					}
					result = num2;
				}
				else
				{
					int num3 = this.int_0[0];
					for (int i = 1; i < num; i++)
					{
						num3 = GF256.smethod_0(this.gf256_0.method_4(int_1, num3), this.int_0[i]);
					}
					result = num3;
				}
			}
			return result;
		}
		internal Class0 method_5(Class0 class0_0)
		{
			if (!this.gf256_0.Equals(class0_0.gf256_0))
			{
				throw new ArgumentException("GF256Polys do not have same GF256 field");
			}
			Class0 result;
			if (this.method_2())
			{
				result = class0_0;
			}
			else
			{
				if (class0_0.method_2())
				{
					result = this;
				}
				else
				{
					int[] array = this.int_0;
					int[] array2 = class0_0.int_0;
					if (array.Length > array2.Length)
					{
						int[] array3 = array;
						array = array2;
						array2 = array3;
					}
					int[] array4 = new int[array2.Length];
					int num = array2.Length - array.Length;
					Array.Copy(array2, 0, array4, 0, num);
					for (int i = num; i < array2.Length; i++)
					{
						array4[i] = GF256.smethod_0(array[i - num], array2[i]);
					}
					result = new Class0(this.gf256_0, array4);
				}
			}
			return result;
		}
		internal Class0 method_6(Class0 class0_0)
		{
			if (!this.gf256_0.Equals(class0_0.gf256_0))
			{
				throw new ArgumentException("GF256Polys do not have same GF256 field");
			}
			Class0 result;
			if (this.method_2() || class0_0.method_2())
			{
				result = this.gf256_0.Zero;
			}
			else
			{
				int[] array = this.int_0;
				int num = array.Length;
				int[] array2 = class0_0.int_0;
				int num2 = array2.Length;
				int[] array3 = new int[num + num2 - 1];
				for (int i = 0; i < num; i++)
				{
					int int_ = array[i];
					for (int j = 0; j < num2; j++)
					{
						array3[i + j] = GF256.smethod_0(array3[i + j], this.gf256_0.method_4(int_, array2[j]));
					}
				}
				result = new Class0(this.gf256_0, array3);
			}
			return result;
		}
		internal Class0 method_7(int int_1)
		{
			Class0 result;
			if (int_1 == 0)
			{
				result = this.gf256_0.Zero;
			}
			else
			{
				if (int_1 == 1)
				{
					result = this;
				}
				else
				{
					int num = this.int_0.Length;
					int[] array = new int[num];
					for (int i = 0; i < num; i++)
					{
						array[i] = this.gf256_0.method_4(this.int_0[i], int_1);
					}
					result = new Class0(this.gf256_0, array);
				}
			}
			return result;
		}
		internal Class0 method_8(int int_1, int int_2)
		{
			if (int_1 < 0)
			{
				throw new ArgumentException();
			}
			Class0 result;
			if (int_2 == 0)
			{
				result = this.gf256_0.Zero;
			}
			else
			{
				int num = this.int_0.Length;
				int[] array = new int[num + int_1];
				for (int i = 0; i < num; i++)
				{
					array[i] = this.gf256_0.method_4(this.int_0[i], int_2);
				}
				result = new Class0(this.gf256_0, array);
			}
			return result;
		}
		internal Class0[] method_9(Class0 class0_0)
		{
			if (!this.gf256_0.Equals(class0_0.gf256_0))
			{
				throw new ArgumentException("GF256Polys do not have same GF256 field");
			}
			if (class0_0.method_2())
			{
				throw new ArgumentException("Divide by 0");
			}
			Class0 @class = this.gf256_0.Zero;
			Class0 class2 = this;
			int int_ = class0_0.method_3(class0_0.method_1());
			int int_2 = this.gf256_0.method_3(int_);
			while (class2.method_1() >= class0_0.method_1() && !class2.method_2())
			{
				int num = class2.method_1() - class0_0.method_1();
				int num2 = this.gf256_0.method_4(class2.method_3(class2.method_1()), int_2);
				Class0 class0_ = class0_0.method_8(num, num2);
				Class0 class0_2 = this.gf256_0.method_0(num, num2);
				@class = @class.method_5(class0_2);
				class2 = class2.method_5(class0_);
			}
			return new Class0[]
			{
				@class,
				class2
			};
		}
		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder(8 * this.method_1());
			for (int i = this.method_1(); i >= 0; i--)
			{
				int num = this.method_3(i);
				if (num != 0)
				{
					if (num < 0)
					{
						stringBuilder.Append(" - ");
						num = -num;
					}
					else
					{
						if (stringBuilder.get_Length() > 0)
						{
							stringBuilder.Append(" + ");
						}
					}
					if (i == 0 || num != 1)
					{
						int num2 = this.gf256_0.method_2(num);
						if (num2 == 0)
						{
							stringBuilder.Append('1');
						}
						else
						{
							if (num2 == 1)
							{
								stringBuilder.Append('a');
							}
							else
							{
								stringBuilder.Append("a^");
								stringBuilder.Append(num2);
							}
						}
					}
					if (i != 0)
					{
						if (i == 1)
						{
							stringBuilder.Append('x');
						}
						else
						{
							stringBuilder.Append("x^");
							stringBuilder.Append(i);
						}
					}
				}
			}
			return stringBuilder.ToString();
		}
	}
}
